<template>
    <div id="suggestions">
        <textarea v-show="lang=='zh'" v-model="content" placeholder="请输入您的宝贵意见或建议..."></textarea>
        <textarea v-show="lang=='en'" v-model="content" placeholder="Please input your valuable opinions or suggestions"></textarea>
        <div v-show="lang=='zh'" class="btn" @click="postsuggestion">提交</div>
        <div v-show="lang=='en'" class="btn" @click="postsuggestion">submit</div>
    </div>
</template>
<script>
import {Toast,} from 'vant';
import {postSuggestion} from '@/api/my/userInfo'
export default {
    name:'suggestions',
    //声明组件
    components:{
        [Toast.name]:Toast,
    },
    data (){
        return{
            lang:'zh',  //语言环境
            userId:0,//用户ID
            content:'',//意见内容
        }
    },
    //实例创建完成后被立即调用
    created (){
        this.getLang();
        this.getUserId();
    },
    //监听
    watch:{

    },
    //计算属性
    computed:{

    },
    //
    methods:{
        //获取用户ID
    	getUserId(){
            if(this.$route.query.userId && this.$route.query.userId > 0){
    			this.userId = this.$route.query.userId;
    		}else{
                //获取缓存内的用户ID
                this.userId = window.localStorage.getItem("userId");
            }
        },
        //获取语言环境
    	getLang(){
            if(this.$route.query.lang){
    			this.lang = this.$route.query.lang;
    		}
        },
        postsuggestion(){
             postSuggestion(this.userId,this.content,this.lang).then(res=>{
                if(res.code==200){
                    if(this.lang == "zh"){
                        Toast("反馈成功！")
                    }else
                        Toast("Submit Success！")
                    let _this = this;
                    setTimeout(function(){ 
                        //返回上一页
                        var para = {};
                        para.isRefresh = true;
                        _this.interaction.hReturn(para);	
                    }, 2000);
                }else{
                    Toast(res.msg)
                }
            });

        }
    }
    
}
</script>

<style lang="stylus" scoped>
*{
    box-sizing :border-box;
}
textarea{
    width :100%;
    height :4.48rem;
    padding :.266667rem;
    font-family:PingFangSC-Regular;
    font-size:.346667rem;
    color:black;
    text-align:left;
}
.btn{
    position :fixed;
    bottom :0;
    width :100%;
    height :1.2rem;
    line-height :1.2rem;
    text-align :center;
    opacity:0.9;
    background:#cb9c57;
    box-shadow:0 0 8px 0 rgba(0,0,0,0.08);
    font-family:PingFangSC-Medium;
    font-size:.4rem;
    color:#ffffff;
    letter-spacing:.0056rem;
}
//输入框的默认字体设置
input::-webkit-input-placeholder, textarea::-webkit-input-placeholder {
    color: #a2a2a2;
}
input:-moz-placeholder, textarea:-moz-placeholder {
    color: #a2a2a2;
}
input:-ms-input-placeholder, textarea:-ms-input-placeholder {
    color: #a2a2a2;
}
</style>


